package com.xcity.packet;

import com.xcity.game.common.MessageConst;
import com.xcity.pomelo.PomeloRoute;
import com.xcity.pomelo.response.HintResponse;

import gnu.trove.set.TShortSet;
import gnu.trove.set.hash.TShortHashSet;
import naga.x.App;
import naga.x.net.Packet;
import naga.x.net.PacketFilter;
import naga.x.net.Session;
import naga.x.net.impl.pomelo.PomeloPacket;
import naga.x.net.impl.pomelo.config.Dictionary;

public class PlayerFilter implements PacketFilter {

	private TShortSet ignoreOpcodes = new TShortHashSet();

	public PlayerFilter() {
		Dictionary dict = App.getApp().getConfig().getDictionary();
		ignoreOpcodes.add(dict.getRouteCode(PomeloRoute.LOGIN));
		ignoreOpcodes.add(dict.getRouteCode(PomeloRoute.REGISTER));
		ignoreOpcodes.add(dict.getRouteCode(PomeloRoute.PLAYER_LOAD));
//		ignoreOpcodes.add(dict.getRouteCode(PomeloRoute.WEIXIN_RECHARGE_OLD));
	}

	@Override
	public boolean filter(Session session, Packet packet) {
		if (ignoreOpcodes.contains(packet.getOpCode())) {
			return true;
		}
		if (session.getClient() != null) {
			return true;
		}
		PomeloPacket pp = (PomeloPacket) packet;
		session.send(new HintResponse(pp.getSerial(), MessageConst.NO_LOGIN));
		return false;
	}
}
